<?php
/*
Plugin Name: dKret Search widget
Description: Adds a sidebar widget to search site.
Author: J. Kretzschmar
Version: 1.1
Author URI: http://diekretzschmars.de
*/

function widget_dkret_search($args) {
	extract($args);
	$options = get_option('widget_dkret_search');
	$title = empty($options['title']) ? __('Search','dkret') : $options['title'];
	echo "$before_widget";
		echo "$before_title"."<label for=\"s\">".$title."</label>".$after_title;?>
					<form id="searchform" method="get" action="<?php bloginfo('home') ?>">
						<div>
							<input id="s" class="text" name="s" type="text" value="<?php the_search_query() ?>" size="10" tabindex="1" accesskey="S" />
							<input id="searchsubmit" class="button" name="searchsubmit" type="submit" value="<?php _e('Find', 'dkret') ?>" tabindex="2" />
						</div>
					</form>
<?php
	echo "$after_widget";
}

// Admin section
function widget_control_dkret_search() {
 	global $wpdb;
 	$options = get_option('widget_dkret_search');
    		
	if ( $_POST['dkret-submit'] ) {

		$options['title'] = strip_tags(stripslashes($_POST['dkret-search-title']));
		update_option('widget_dkret_search', $options);
	}
	
	$title = htmlspecialchars($options['title'], ENT_QUOTES);
	
	// The Box content
	echo '<p style="text-align:right;"><label for="dkret-search-title" />' . __('Title:') . ' <input style="width: 200px;" id="dkret-search-title" name="dkret-search-title" type="text" value="'.$title.'" /></p>';
	echo '<input type="hidden" id="dkret-submit" name="dkret-submit" value="1" />';
}

$widget_ops = array('classname' => 'widget_dkret_search', 'description' => __( "A search form for your blog (dkret)", 'dkret') );
wp_register_sidebar_widget('search', __('Search'), 'widget_dkret_search', $widget_ops);
unregister_widget_control('search');
wp_register_widget_control('search', __('Search'), 'widget_control_dkret_search');

?>